﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business
{
    public partial class SystemParameters : Form
    {
        public SystemParameters()
        {
            InitializeComponent();
            getjilu();
        }
        public void getjilu()
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"select * from xitongcanshupeizhi order by xtpz_csmc ");
            DataTable dt = objquery.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                com_mingchen.Items.Add(dt.Rows[i]["xtpz_csmc"].ToString().Trim());
                if (i == 0)
                    com_mingchen.Text = dt.Rows[0]["xtpz_csmc"].ToString().Trim();
            }
        }

        private void but_save_Click(object sender, EventArgs e)
        {
            string scszlx = "";
            if (radioButton1.Checked)
            {
                scszlx = "系统参数";
            }
            else if (radioButton2.Checked)
            {
                scszlx = "部门参数";
            }


            string ssyfw = "";

            if (radioButton3.Checked)
            {
                ssyfw = "字符";
            }
            else if (radioButton4.Checked)
            {
                ssyfw = "整数";
            }
            else if (radioButton5.Checked)
            {
                ssyfw = "小数";
            }
            else if (radioButton6.Checked)
            {
                ssyfw = "日期";
            }

            string sjzfs = "";
            if (radioButton7.Checked)
            {
                sjzfs = "终端";
            }
            else if (radioButton8.Checked)
            {
                sjzfs = "后台";
            }

            string szhuangtai = "";

            if (radioButton12.Checked)
            {
                szhuangtai = "有效";
            }
            else if (radioButton13.Checked)
            {
                szhuangtai = "无效";
            }
            Query objquery = new Query();
            string ssql = "";
            ssql = string.Format(@"Select count(*) From xitongcanshupeizhi where xtpz_csmc='{0}'", com_mingchen.Text);
            if (objquery.ExecuteS(ssql))
            {
                ssql = string.Format(@"update  xitongcanshupeizhi 
                                       set xtpz_csdm='{0}' ,
                                        xtpz_cssm='{1}' ,
                                        xtpz_csz='{2}' ,
                                        xtpz_cslx='{3}' ,
                                        xtpz_cszlx='{4}',
                                        xtpz_csjb='{5}',
                                        xtpz_syfw='{6}',
                                        xtpz_cssx='{7}',
                                        xtpz_px='{8}',
                                        xtpz_zt='{9}'
                                        where xtpz_csmc='{10}'",
                                                text_csdm.Text,
                                                com_cssm.Text,
                                                text_zhi.Text,
                                                scszlx,
                                                tex_csjb.Text,
                                                ssyfw,
                                                text_cssx.Text,
                                                sjzfs,
                                                text_paixu.Text,
                                                szhuangtai,
                                                com_mingchen.Text);
            }
            else
            {
                ssql = string.Format(@"insert into xitongcanshupeizhi (
                                        xtpz_csdm,
                                        xtpz_csmc,
                                        xtpz_cssm,
                                        xtpz_csz,
                                        xtpz_cslx,
                                        xtpz_cszlx,
                                        xtpz_csjb,
                                        xtpz_syfw,
                                        xtpz_cssx,
                                        xtpz_px,
                                        xtpz_zt) values 
                                        ('{0}',
                                        '{1}',
                                        '{2}',
                                        '{3}',
                                        '{4}',
                                        '{5}',
                                        '{6}',
                                        '{7}',
                                        '{8}',
                                        '{9}',
                                        '{10}')", text_csdm.Text,
                                                com_mingchen.Text,
                                                 com_cssm.Text,
                                                text_zhi.Text,
                                                scszlx,
                                                tex_csjb.Text,
                                                ssyfw,
                                                text_cssx.Text,
                                                sjzfs,
                                                text_paixu.Text,
                                                szhuangtai);
            }
            if (!objquery.UpdateTable(ssql))
            {
                MessageBox.Show("添加失败");
            }
            else
            {
                MessageBox.Show("添加成功");
            }
        }

        private void but_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void com_mingchen_SelectedIndexChanged(object sender, EventArgs e)
        {
            getneirong();
        }
        public void getneirong()
        {
            string sql = string.Format(@"Select * From xitongcanshupeizhi where xtpz_csmc='{0}' ", com_mingchen.Text);

            Query mquery = new Query();
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {

                text_csdm.Text = dt.Rows[0]["xtpz_csdm"].ToString().Trim();
                com_cssm.Text = dt.Rows[0]["xtpz_cssm"].ToString().Trim();
                text_zhi.Text = dt.Rows[0]["xtpz_csz"].ToString().Trim();
                if (dt.Rows[0]["xtpz_cslx"].ToString().Trim().Contains("系统参数"))
                {
                    radioButton1.Checked = true;
                    radioButton2.Checked = false;
                }
                else if (dt.Rows[0]["xtpz_cslx"].ToString().Trim().Contains("部门参数"))
                {
                    radioButton1.Checked = false;
                    radioButton2.Checked = true;
                }

                tex_csjb.Text = dt.Rows[0]["xtpz_csjb"].ToString().Trim();
                if (dt.Rows[0]["xtpz_syfw"].ToString().Trim().Contains("字符"))
                {
                    radioButton3.Checked = true;
                    radioButton4.Checked = false;
                    radioButton5.Checked = false;
                    radioButton6.Checked = false;
                }
                else if (dt.Rows[0]["xtpz_syfw"].ToString().Trim().Contains("整数"))
                {
                    radioButton3.Checked = false;
                    radioButton4.Checked = true;
                    radioButton5.Checked = false;
                    radioButton6.Checked = false;
                }
                else if (dt.Rows[0]["xtpz_syfw"].ToString().Trim().Contains("小数"))
                {
                    radioButton3.Checked = false;
                    radioButton4.Checked = false;
                    radioButton5.Checked = true;
                    radioButton6.Checked = false;
                }
                else if (dt.Rows[0]["xtpz_syfw"].ToString().Trim().Contains("日期"))
                {
                    radioButton3.Checked = false;
                    radioButton4.Checked = false;
                    radioButton5.Checked = false;
                    radioButton6.Checked = true;
                }

                text_cssx.Text = dt.Rows[0]["xtpz_cssx"].ToString().Trim();
                if (dt.Rows[0]["xtpz_jzfs"].ToString().Trim().Contains("终端"))
                {
                    radioButton7.Checked = true;
                    radioButton8.Checked = false;
                }
                else if (dt.Rows[0]["xtpz_jzfs"].ToString().Trim().Contains("后台"))
                {
                    radioButton7.Checked = false;
                    radioButton8.Checked = true;
                }
                text_paixu.Text = dt.Rows[0]["xtpz_px"].ToString().Trim();
                if (dt.Rows[0]["xtpz_zt"].ToString().Trim().Contains("有效"))
                {
                    radioButton12.Checked = true;
                    radioButton13.Checked = false;
                }
                else if (dt.Rows[0]["xtpz_zt"].ToString().Trim().Contains("无效"))
                {
                    radioButton12.Checked = false;
                    radioButton13.Checked = true;
                }


            }
        }
    }
}
